package org.kolyas.ui;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import org.kolyas.domain.GoodBean;

public class GoodsTableModel extends AbstractTableModel {

	private List<GoodBean> listOfGoods;
	private String[] columnNames =	new String[] {"Code", "Name", "Price"};
	private Class[] columnTypes = new Class[] {Integer.class, String.class, Integer.class};

	public Class getColumnClass(int columnIndex) {
		return columnTypes[columnIndex];
	}
	
	@Override
	public int getRowCount() {
		// TODO Auto-generated method stub
		return listOfGoods.size();
	}

	@Override
	public int getColumnCount() {
		// TODO Auto-generated method stub
		return 3;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		// TODO Auto-generated method stub
		GoodBean good = listOfGoods.get(rowIndex);
		if (columnIndex==0){
			return good.code;
		}
		if (columnIndex==1){
			return good.name;
		}
		if (columnIndex==2){
			return good.price;
		}
		return null;
	}
	
    public String getColumnName(int column) {
        return columnNames[column];
    }
	
	public GoodsTableModel(List<GoodBean> list) {
		listOfGoods = list;
	}

}
